 
package com.zdkj.subway.rca.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.out.*;
import com.zdkj.subway.rca.entity.SwCkCycleStockSale;
import com.zdkj.subway.rca.mapper.SwCkCycleStockSaleMapper;
import com.zdkj.subway.rca.service.SwCkCycleStockSaleService;
import com.zdkj.subway.rca.util.LocalDateConverter;
import com.zdkj.subway.rca.util.LocalDateTimeConverter;
import com.zdkj.subway.rca.util.MyBeanUtils;
import com.zdkj.subway.rca.util.MyDateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 周期内库存售卖表
 *   1. 上日结存数量：车站车票库存日报表已经审核状态对应票种的上日结存数量
     2. 现库存张数：库存日报表的本日结存数量
     3. 售卖数量：库存日报表票种中的票房售出+TVM售出+网络售出数量合计（减去即时退换票的数量）
     4. 售卖金额：售卖数量*票种对应的单价-营销车票团购中的折扣率算出来的金额
     5. 收入统计合计：西安地铁收入调账日报表中，分票种的线路合计金额（预制票、应急票、日票、计次、纪念票）（加上转账、线下和团购的金额）
 * @author stw
 * @date 2020-11-24 11:11:45
 */
@Service
public class SwCkCycleStockSaleServiceImpl extends ServiceImpl<SwCkCycleStockSaleMapper, SwCkCycleStockSale> implements SwCkCycleStockSaleService {
    private static final Logger log = LoggerFactory.getLogger(SwCkCycleStockSaleServiceImpl.class);
    /**
     * 产生数据
     * @return
     */
    @Override
    public Boolean generate(String startDate,String endDate) throws Exception {

        //根据日期范围获取数据list
        List<Map<String,Object>> swStStockList = this.baseMapper.getSwStStockList(startDate,endDate);
        List<Map<String,Object>> swPmTicketCardTypeParamList = this.baseMapper.getSwPmTicketCardTypeParamList(startDate,endDate);
        List<Map<String,Object>> swCkStationDailyReportAdjustList = this.baseMapper.getSwCkStationDailyReportAdjustList(startDate,endDate);

        List<SwCkCycleStockSale> updaeList = new ArrayList<>();
        List<SwCkCycleStockSale> insertList = new ArrayList<>();

        PigxUser user = SecurityUtils.getUser();

        //循环swStStockList
        for(Map<String,Object> swStStock : swStStockList) {
            SwCkCycleStockSale insertObj = new SwCkCycleStockSale();
            insertObj.setLineCode((String)swStStock.get("LINE_CODE"));
            insertObj.setStatisticalTime(LocalDate.parse((String)swStStock.get("STATISTICAL_TIME"), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
			String ticketTypeEn = (String)swStStock.get("TICKET_TYPE");
			//票种名称
            if("YZDCP".equals(ticketTypeEn)){
                insertObj.setTicketType("预制单程票");
            } else if("YJZP".equals(ticketTypeEn)){
                insertObj.setTicketType("应急纸票");
            } else if("YXCP1".equals(ticketTypeEn)){
                insertObj.setTicketType("纪念票");
            } else if("YXCP2".equals(ticketTypeEn)){
                insertObj.setTicketType("日票");
            } else if("YXCP3".equals(ticketTypeEn)){
                insertObj.setTicketType("计次票");
            }          
            
            //数据库老的
            SwCkCycleStockSale dbSwCkCycleStockSale = this.getOne(Wrappers.query(insertObj));
            if (dbSwCkCycleStockSale != null){
                insertObj.setId(dbSwCkCycleStockSale.getId());
            }
            //上日结存数量(张)（线网库存表）
            insertObj.setLastDayBalanceQuantity(((BigDecimal)swStStock.get("LAST_DAY_BALANCE_QUANTITY")).longValue());
            //现库存数量（线网库存表）
            insertObj.setCurrentStockQuantity(((BigDecimal)swStStock.get("CURRENT_STOCK_QUANTITY")).longValue());
            //售卖数量
            insertObj.setSoldQuantity(((BigDecimal)swStStock.get("SOLD_QUANTITY")).longValue());

            //BigDecimal ticketAount = (BigDecimal)ticketTypeMap.get("TICKET_AMOUNT"); //单价
			BigDecimal soldMoney = ((BigDecimal)swStStock.get("SOLD_MONEY"));
            //售卖金额（元）
            //insertObj.setSoldAmount(new BigDecimal(insertObj.getSoldQuantity()).multiply(ticketAount).subtract((BigDecimal)swStStock.get("SOLD_AMOUNT2")));
			//insertObj.setSoldAmount(soldMoney.subtract((BigDecimal)swStStock.get("SOLD_AMOUNT2")));
			insertObj.setSoldAmount(soldMoney);//不需要减去营销车票金额

            //收入金额（数据调整最终  统计）（元）
            Map<String,Object> incomeAmountMap =  geIncomeAmount(insertObj.getLineCode(),insertObj.getStatisticalTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),swCkStationDailyReportAdjustList);
            BigDecimal incomeAmount = new BigDecimal(0);
            if(incomeAmountMap != null){

                if("YZDCP".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("PREFABRICATED_TICKET_AMOUNT");
                } else if("YJZP".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("EMERGENCY_TICKET_AMOUNT");
                } else if("YXCP1".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("COMMEMORATIVE_TICKET_SUB_TOTAL");
                } else if("YXCP2".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("DAILY_SUB_TOTAL");
					//log.info("日票金额============="+incomeAmount);
                } else if("YXCP3".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("TICKET_COUNTING");
                }
            }

            //收入金额（数据调整最终  统计）（元）
            insertObj.setIncomeAmount(incomeAmount);

            //差异金额（元）
            insertObj.setDifferenceAmount(insertObj.getIncomeAmount().subtract(insertObj.getSoldAmount()));

            //线路名称
            insertObj.setLineName((String)swStStock.get("LINE_NAME"));

            insertObj.setDeptId(user.getDeptId());
            insertObj.setCreatorId(user.getId());
            insertObj.setCreatorName(user.getNikeName());
            if(insertObj.getId() != null){
                updaeList.add(insertObj);
            } else {
                insertList.add(insertObj);
            }
        }
        boolean flag = false;
        boolean flag2 = false;
        if(!updaeList.isEmpty()){
            //合并同类票种
            //updaeList = sumTicketType(updaeList);
            flag = this.updateBatchById(updaeList);
        }
        if(!insertList.isEmpty()){
            //合并同类票种
            //insertList = sumTicketType(insertList);
            flag2 = this.saveBatch(insertList);
        }
        return  flag || flag2;
    }

	/*
	 @Override
    public Boolean generate(String startDate,String endDate) throws Exception {

        //根据日期范围获取数据list
        List<Map<String,Object>> swStStockList = this.baseMapper.getSwStStockList(startDate,endDate);
        List<Map<String,Object>> swPmTicketCardTypeParamList = this.baseMapper.getSwPmTicketCardTypeParamList(startDate,endDate);
        List<Map<String,Object>> swCkStationDailyReportAdjustList = this.baseMapper.getSwCkStationDailyReportAdjustList(startDate,endDate);

        List<SwCkCycleStockSale> updaeList = new ArrayList<>();
        List<SwCkCycleStockSale> insertList = new ArrayList<>();

        PigxUser user = SecurityUtils.getUser();

        //循环swStStockList
        for(Map<String,Object> swStStock : swStStockList) {
            SwCkCycleStockSale insertObj = new SwCkCycleStockSale();
            insertObj.setLineCode((String)swStStock.get("LINE_CODE"));
            insertObj.setStatisticalTime(LocalDate.parse((String)swStStock.get("STATISTICAL_TIME"), DateTimeFormatter.ofPattern("yyyy-MM-dd")));

            Map<String,Object> ticketTypeMap = getTicketType((String)swStStock.get("TICKET_TYPE_PARAM_EN"), swPmTicketCardTypeParamList);
            String ticketTypeEn = "";
            if(ticketTypeMap != null){
                ticketTypeEn = (String)ticketTypeMap.get("TICKET_TYPE");
            }
            //票种名称
            if("YZDCP".equals(ticketTypeEn)){
                insertObj.setTicketType("预制单程票");
            } else if("YJZP".equals(ticketTypeEn)){
                insertObj.setTicketType("应急纸票");
            } else if("YXCP1".equals(ticketTypeEn)){
                insertObj.setTicketType("纪念票");
            } else if("YXCP2".equals(ticketTypeEn)){
                insertObj.setTicketType("日票");
            } else if("YXCP3".equals(ticketTypeEn)){
                insertObj.setTicketType("计次票");
            }
            //数据库老的
            SwCkCycleStockSale dbSwCkCycleStockSale = this.getOne(Wrappers.query(insertObj));
            if (dbSwCkCycleStockSale != null){
                insertObj.setId(dbSwCkCycleStockSale.getId());
            }
            //上日结存数量(张)（线网库存表）
            insertObj.setLastDayBalanceQuantity(((BigDecimal)swStStock.get("LAST_DAY_BALANCE_QUANTITY")).longValue());
            //现库存数量（线网库存表）
            insertObj.setCurrentStockQuantity(((BigDecimal)swStStock.get("CURRENT_STOCK_QUANTITY")).longValue());
            //售卖数量
            insertObj.setSoldQuantity(((BigDecimal)swStStock.get("SOLD_QUANTITY")).longValue());

            BigDecimal ticketAount = (BigDecimal)ticketTypeMap.get("TICKET_AMOUNT"); //单价
            //售卖金额（元）
            insertObj.setSoldAmount(new BigDecimal(insertObj.getSoldQuantity()).multiply(ticketAount).subtract((BigDecimal)swStStock.get("SOLD_AMOUNT2")));

            //收入金额（数据调整最终  统计）（元）
            Map<String,Object> incomeAmountMap =  geIncomeAmount(insertObj.getLineCode(),insertObj.getStatisticalTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),swCkStationDailyReportAdjustList);
            BigDecimal incomeAmount = new BigDecimal(0);
            if(incomeAmountMap != null){

                if("YZDCP".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("PREFABRICATED_TICKET_AMOUNT");
                } else if("YJZP".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("EMERGENCY_TICKET_AMOUNT");
                } else if("YXCP1".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("COMMEMORATIVE_TICKET_SUB_TOTAL");
                } else if("YXCP2".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("DAILY_SUB_TOTAL");
                } else if("YXCP3".equals(ticketTypeEn)){
                    incomeAmount = (BigDecimal)incomeAmountMap.get("TICKET_COUNTING");
                }
            }

            //收入金额（数据调整最终  统计）（元）
            insertObj.setIncomeAmount(incomeAmount);

            //差异金额（元）
            insertObj.setDifferenceAmount(insertObj.getIncomeAmount().subtract(insertObj.getSoldAmount()));

            //线路名称
            insertObj.setLineName((String)swStStock.get("LINE_NAME"));

            insertObj.setDeptId(user.getDeptId());
            insertObj.setCreatorId(user.getId());
            insertObj.setCreatorName(user.getNikeName());
            if(insertObj.getId() != null){
                updaeList.add(insertObj);
            } else {
                insertList.add(insertObj);
            }
        }
        boolean flag = false;
        boolean flag2 = false;
        if(!updaeList.isEmpty()){
            //合并同类票种
            updaeList = sumTicketType(updaeList);
            flag = this.updateBatchById(updaeList);
        }
        if(!insertList.isEmpty()){
            //合并同类票种
            insertList = sumTicketType(insertList);
            flag2 = this.saveBatch(insertList);
        }
        return  flag || flag2;
    }
	
	*/

    private  List<SwCkCycleStockSale> sumTicketType(List<SwCkCycleStockSale> list){
        Set<Map<String,Object>> set = new HashSet<>();

        for(SwCkCycleStockSale obj : list) {
            Map<String,Object> tmp = new HashMap<>();
            tmp.put("lineCode",obj.getLineCode());
            tmp.put("statisticalTime",obj.getStatisticalTime());
            tmp.put("ticketType",obj.getTicketType());
            set.add(tmp);
        }
        List<SwCkCycleStockSale> rtnList = new ArrayList<>();
        for(Map<String,Object> typeObj : set){
            SwCkCycleStockSale rtn = null;
            for(SwCkCycleStockSale obj : list) {
                if(typeObj.get("lineCode").equals(obj.getLineCode())
                        && typeObj.get("statisticalTime").equals(obj.getStatisticalTime())
                         && typeObj.get("ticketType").equals(obj.getTicketType())) {
                    if(rtn == null){
                        rtn = new SwCkCycleStockSale();
                        MyBeanUtils.copyProperties(obj,rtn);
                    } else {
                        rtn.setLastDayBalanceQuantity(rtn.getLastDayBalanceQuantity() + obj.getLastDayBalanceQuantity());
                        rtn.setCurrentStockQuantity(rtn.getCurrentStockQuantity() + obj.getCurrentStockQuantity());
                        rtn.setSoldQuantity(rtn.getSoldQuantity() + obj.getCurrentStockQuantity());
                        rtn.setSoldAmount(rtn.getSoldAmount().add(obj.getSoldAmount()));
                        rtn.setIncomeAmount(rtn.getIncomeAmount().add(obj.getIncomeAmount()));
                        rtn.setDifferenceAmount(rtn.getDifferenceAmount().add(obj.getDifferenceAmount()));
                    }
                }
            }
            rtnList.add(rtn);
        }
        return rtnList;
    }

    private Map<String,Object> getTicketType(String type,  List<Map<String,Object>> swPmTicketCardTypeParamList){
        if(swPmTicketCardTypeParamList == null || swPmTicketCardTypeParamList.isEmpty()) {
            return null;
        }
        for(Map<String,Object> map : swPmTicketCardTypeParamList) {
            if(type.equals(map.get("SUB_EN_NAME"))){
                return map;
            }
        }
        return null;
    }

    private Map<String,Object> geIncomeAmount(String lineCode,String statisticalTime,  List<Map<String,Object>> swCkStationDailyReportAdjustList){
        if(swCkStationDailyReportAdjustList == null || swCkStationDailyReportAdjustList.isEmpty()) {
            return null;
        }
        for(Map<String,Object> map : swCkStationDailyReportAdjustList) {			
            if(lineCode.equals(map.get("LINE_CODE")) && statisticalTime.equals(map.get("STATISTICAL_TIME"))) {
			
                return map;
            }
        }
        return null;
    }

    @Override
    public void exportSwCkCycleStockSale(String startDate, String endDate,String lineCode,String ticketType,HttpServletResponse response) {
        SwCkCycleStockSale swCkCycleStockSale = new SwCkCycleStockSale();
        swCkCycleStockSale.setLineCode(lineCode);
		if(ticketType!=null && !"".equals(ticketType)){
		  swCkCycleStockSale.setTicketType(ticketType);
		}

		QueryWrapper<SwCkCycleStockSale> lambdaQueryWrapper = Wrappers.query(swCkCycleStockSale);
        lambdaQueryWrapper.lambda().ge(StringUtils.isNotEmpty(startDate), SwCkCycleStockSale::getStatisticalTime, startDate).le( StringUtils.isNotEmpty(endDate),SwCkCycleStockSale::getStatisticalTime, endDate);
        lambdaQueryWrapper.orderByAsc("LINE_CODE");
		lambdaQueryWrapper.orderByAsc("STATISTICAL_TIME");	
		List<SwCkCycleStockSale> records = this.list(lambdaQueryWrapper);

		//
		/*
		QueryWrapper<SwCkCycleStockSale> queryWrappers = Wrappers.query(swCkCycleStockSale);
		queryWrappers.lambda().ge(StringUtils.isNotEmpty(startDate), SwCkCycleStockSale::getStatisticalTime, startDate)
        queryWrappers.orderByAsc("LINE_CODE");
        queryWrappers.orderByAsc("STATISTICAL_TIME");
        List<SwCkCycleStockSale> list = this.list(queryWrappers);
		//
        List<SwCkCycleStockSale> records = this.list(Wrappers.query(swCkCycleStockSale).lambda().ge(StringUtils.isNotEmpty(startDate), SwCkCycleStockSale::getStatisticalTime, startDate).le( StringUtils.isNotEmpty(endDate),SwCkCycleStockSale::getStatisticalTime, endDate));
        */
        InputStream excelTemplateIs = null;
        try {response.reset(); // 非常重要
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            final String fileName = URLEncoder.encode("周期内库存售卖", "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

            // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
            // {} 代表普通变量 {.} 代表是list的变量

            excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkCycleStockSaleExcelTemplate.xlsx");

            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();
            WriteSheet writeSheet = EasyExcel.writerSheet("周期内库存售卖").build();
            // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
            // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
            // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
            // 如果数据量大 list不是最后一行 参照另一个
            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.FALSE).build();
            excelWriter.fill(records, fillConfig, writeSheet);
            excelWriter.finish();

        } catch (Exception e) {
            e.printStackTrace();
            log.error("导出周期内库存售卖错误");
        } finally {
            if(excelTemplateIs != null){
                try {
                    excelTemplateIs.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }

            }
        }
    }
	/**
     * 导出日票售卖统计表--票卡
     * @param
     * @return
     * @throws IOException
     */
    @Override
    public void exportDailyTicketByCard(String startDate, String endDate,HttpServletResponse response){
		//日期--按单个车站组织
		List<Map<String,Object>>  listMapSingleStations = this.baseMapper.getSwCkDailyTicketSaleByCardByStation(startDate,endDate);
		List<SwCkDailyTicketSaleExportDTO> listSingleStations  = combinAttribute(listMapSingleStations,true,true);
		//日期 - 车站合计
		List<Map<String,Object>>  listMapStationTotal = this.baseMapper.getSwCkDailyTicketSaleByCardByStationTotal(startDate,endDate);
		List<SwCkDailyTicketSaleExportDTO> listStationTotal  = combinAttribute(listMapStationTotal,false,true);

		//日期 - 日期合计
		List<Map<String,Object>> listMapDay  = this.baseMapper.getSwCkDailyTicketSaleByCardByDateTotal(startDate,endDate);
		List<SwCkDailyTicketSaleExportDTO> listDay  =  combinAttribute(listMapDay,true,false);
        
		List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
		Map<String, List<SwCkDailyTicketSaleExportDTO>> map = new LinkedHashMap<>();
        Map<String, String> mapLocalName = new HashMap<>();

//        if(CollectionUtils.isNotEmpty(stationMap) && CollectionUtils.isNotEmpty(listSingleStations) ){
        if(CollectionUtils.isNotEmpty(stationMap)){
        //车站循环,每个车站只有一个合计
			for (Map<String,String> mapStations : stationMap) {
				 String stationCode = mapStations.get("CODE");
				 String stationName = mapStations.get("NAME");

                List<SwCkDailyTicketSaleExportDTO> records  = new ArrayList<>();


				 SwCkDailyTicketSaleExportDTO swCkSingleStationSum = new SwCkDailyTicketSaleExportDTO();
                if(CollectionUtils.isNotEmpty(listSingleStations)){
                    //按车站分组，过滤出对应车站的数据
                    List<SwCkDailyTicketSaleExportDTO> collect = listSingleStations.stream().filter(x -> stationCode.equals(x.getStationCode())).collect(Collectors.toList());
                    for(SwCkDailyTicketSaleExportDTO obj : collect) {
                        adjustForm(obj,swCkSingleStationSum,false);//求合计值
                        stationSum(listSingleStations, startDate, endDate, swCkSingleStationSum, stationCode);
                        records.add(obj);
                    }
                }

				 records.add(swCkSingleStationSum);//将合计追加到最后一条				 
				 map.put(stationName,records);//这样保证，即使有的车站没数据也不会报错
				 mapLocalName.put(stationName,stationName);//显示车站名称
				 
             }
			InputStream excelTemplateIs = null;
            try {
				response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
				String tmpFileName = "-日票售卖统计表-按票卡-";
                final String fileName = URLEncoder.encode(tmpFileName, "UTF-8");
                response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

                // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                // {} 代表普通变量 {.} 代表是list的变量

                excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkDailyTicketSaleByCardExcelTemplate.xlsx");

                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

                //1. 每个车站的导出
				int i=0;//计数器，创建了多少个Sheet
				for (Map.Entry<String, List<SwCkDailyTicketSaleExportDTO>> integerListEntry : map.entrySet()) {
                    i++;
					String key = integerListEntry.getKey();//存的是车站名字
                    List<SwCkDailyTicketSaleExportDTO> value = integerListEntry.getValue();
                    // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                    // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                    // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                    // 如果数据量大 list不是最后一行 参照另一个
                    //WriteSheet writeSheet = EasyExcel.writerSheet(key-1,String.valueOf(key)).build();
					
					WriteSheet writeSheet = EasyExcel.writerSheet(i-1,key).build();
                    FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(value, fillConfig, writeSheet);
                    Map<String, Object> mapDate = new HashMap<>();
                    mapDate.put("stationName", mapLocalName.get(key));                  
                    excelWriter.fill(mapDate,writeSheet);
                }
                //车站和日期合计，填写日期 是否显示待定
				Map<String, Object> mapOther = new HashMap<>();
                //mapOther.put("lineName",lineName);
				mapOther.put("startDate",startDate);
				mapOther.put("endDate",endDate);

				//2. 日期合计
                List<SwCkDailyTicketSaleExportDTO> recordsDay  = new ArrayList<>();
                SwCkDailyTicketSaleExportDTO swCkSingleStationSum = new SwCkDailyTicketSaleExportDTO();
                if(CollectionUtil.isNotEmpty(listDay)){
                    for(SwCkDailyTicketSaleExportDTO obj : listDay) {
                        obj.setBalanceLastdaySubTotal(obj.getBalanceLastdayYrp()+obj.getBalanceLastdaySrp()+obj.getBalanceLastdayZlljsrp());
                        obj.setBoxOfficeSaleSubtotal(obj.getBoxOfficeSaleYrp()+obj.getBoxOfficeSaleSrp()+obj.getBoxOfficeSaleZlljsrp());
                        obj.setBalanceTodaySubtotal(obj.getBalanceTodayYrp()+obj.getBalanceTodaySrp()+obj.getBalanceTodayZlljsrp());
                        adjustForm(obj,swCkSingleStationSum,true);//求合计值
                        stationSum(listDay, startDate, endDate, swCkSingleStationSum, null);
                        recordsDay.add(obj);
                    }
                }
                recordsDay.add(swCkSingleStationSum);//将合计追加到最后一条

                //必须加上sheetNo,否则会追加
                WriteSheet writeSheetDay = EasyExcel.writerSheet(i,"日期合计").build();
                FillConfig fillConfigDay = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                excelWriter.fill(recordsDay, fillConfigDay, writeSheetDay);
                excelWriter.fill(mapOther, writeSheetDay);

                //3. 车站合计
                List<SwCkDailyTicketSaleExportDTO> recordsStationTotal  = new ArrayList<>();
                SwCkDailyTicketSaleExportDTO swCkSingleStationSum1 = new SwCkDailyTicketSaleExportDTO();
                if(CollectionUtil.isNotEmpty(listStationTotal)){
                    for(SwCkDailyTicketSaleExportDTO obj : listStationTotal) {
                        stationSum(listSingleStations, startDate, endDate, obj, obj.getStationCode());
                        obj.setBalanceLastdaySubTotal(obj.getBalanceLastdayYrp()+obj.getBalanceLastdaySrp()+obj.getBalanceLastdayZlljsrp());
                        obj.setBoxOfficeSaleSubtotal(obj.getBoxOfficeSaleYrp()+obj.getBoxOfficeSaleSrp()+obj.getBoxOfficeSaleZlljsrp());
                        obj.setBalanceTodaySubtotal(obj.getBalanceTodayYrp()+obj.getBalanceTodaySrp()+obj.getBalanceTodayZlljsrp());
                        adjustForm(obj,swCkSingleStationSum1,true);//求合计值，按正常合计计算						
                        recordsStationTotal.add(obj);
                    }
                }
                recordsStationTotal.add(swCkSingleStationSum1);//将合计追加到最后一条
                //必须加上sheetNo,否则会追加
                WriteSheet writeSheetStationAll = EasyExcel.writerSheet(i+1,"车站合计").build();
                FillConfig fillConfigStationAll = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                excelWriter.fill(recordsStationTotal, fillConfigStationAll, writeSheetStationAll);

                excelWriter.fill(mapOther, writeSheetStationAll);

				

				//最后完成
                excelWriter.finish();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("导出日票售卖统计表按票卡导出错误");
            } finally {
                if(excelTemplateIs != null){
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }

                }
            }

			

        }
			
    }

    private static void stationSum(List<SwCkDailyTicketSaleExportDTO> list, String startDate, String endDate, SwCkDailyTicketSaleExportDTO swCkSingleStationSum, String stationCode){
        for (SwCkDailyTicketSaleExportDTO swCkDailyTicketSaleExportDTO : list) {
            String tradeDateTostring = swCkDailyTicketSaleExportDTO.getTradeDateTostring();
            if (stationCode != null) {
                if (tradeDateTostring.equals(startDate)
                        && stationCode.equals(swCkDailyTicketSaleExportDTO.getStationCode())) {
                    swCkSingleStationSum.setBalanceLastdayYrp(swCkDailyTicketSaleExportDTO.getBalanceLastdayYrp());
                    swCkSingleStationSum.setBalanceLastdaySrp(swCkDailyTicketSaleExportDTO.getBalanceLastdaySrp());
                    swCkSingleStationSum.setBalanceLastdayZlljsrp(swCkDailyTicketSaleExportDTO.getBalanceLastdayZlljsrp());
                } else if (tradeDateTostring.equals(endDate)
                        && stationCode.equals(swCkDailyTicketSaleExportDTO.getStationCode())) {
                    swCkSingleStationSum.setBalanceTodayYrp(swCkDailyTicketSaleExportDTO.getBalanceTodayYrp());
                    swCkSingleStationSum.setBalanceTodaySrp(swCkDailyTicketSaleExportDTO.getBalanceTodaySrp());
                    swCkSingleStationSum.setBalanceTodayZlljsrp(swCkDailyTicketSaleExportDTO.getBalanceTodayZlljsrp());
                }
            }

            if (tradeDateTostring.equals(startDate)
                    && stationCode == null) {
                swCkSingleStationSum.setBalanceLastdayYrp(swCkDailyTicketSaleExportDTO.getBalanceLastdayYrp());
                swCkSingleStationSum.setBalanceLastdaySrp(swCkDailyTicketSaleExportDTO.getBalanceLastdaySrp());
                swCkSingleStationSum.setBalanceLastdayZlljsrp(swCkDailyTicketSaleExportDTO.getBalanceLastdayZlljsrp());
                swCkSingleStationSum.setBalanceLastdaySubTotal(swCkSingleStationSum.getBalanceLastdayYrp()
                        + swCkDailyTicketSaleExportDTO.getBalanceLastdaySrp()
                        + swCkDailyTicketSaleExportDTO.getBalanceLastdayZlljsrp());
            } else if (tradeDateTostring.equals(endDate)
                    && stationCode == null) {
                swCkSingleStationSum.setBalanceTodayYrp(swCkDailyTicketSaleExportDTO.getBalanceTodayYrp());
                swCkSingleStationSum.setBalanceTodaySrp(swCkDailyTicketSaleExportDTO.getBalanceTodaySrp());
                swCkSingleStationSum.setBalanceTodayZlljsrp(swCkDailyTicketSaleExportDTO.getBalanceTodayZlljsrp());
                swCkSingleStationSum.setBalanceTodaySubtotal(swCkDailyTicketSaleExportDTO.getBalanceTodayYrp() + swCkDailyTicketSaleExportDTO.getBalanceTodaySrp() + swCkDailyTicketSaleExportDTO.getBalanceTodayZlljsrp());
            }
        }


    }

	/**
     * 导出日票售卖统计表--收益
     * @param
     * @return
     * @throws IOException
     */
    @Override
    public void exportDailyTicketByIncome(String startDate, String endDate,HttpServletResponse response){

		//日期--按单个车站组织
		List<Map<String,Object>>  listMapSingleStations = this.baseMapper.getSwCkDailyTicketSaleByIncomeByStation(startDate,endDate);
		List<SwCkDailyTicketIncomeExportDTO> listSingleStations  = combinIncomeAttribute(listMapSingleStations,true,true);
		//日期 - 车站合计
		List<Map<String,Object>>  listMapStationTotal = this.baseMapper.getSwCkDailyTicketSaleByIncomeByStationTotal(startDate,endDate);
		List<SwCkDailyTicketIncomeExportDTO> listStationTotal  = combinIncomeAttribute(listMapStationTotal,false,true);

		//日期 - 日期合计（合并POS的都调用此方法)
		List<Map<String,Object>> listMapDay  = this.baseMapper.getSwCkDailyTicketSaleByIncomeByPosTotal(startDate,endDate);
		List<SwCkDailyTicketIncomeExportDTO> listDay  =  combinIncomeAttribute(listMapDay,true,false);
        //日期 - 日期合计（有POS调用此方法)
		List<Map<String,Object>> listMapSinglePosDay  = this.baseMapper.getSwCkDailyTicketSaleByIncomeByPosSingleTotal(startDate,endDate);
		List<SwCkDailyTicketIncomeExportDTO> listSinglePosDay  =  combinIncomeAttribute(listMapSinglePosDay,true,false);
        
		List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
		Map<String, List<SwCkDailyTicketIncomeExportDTO>> map = new LinkedHashMap<>();
        Map<String, String> mapLocalName = new HashMap<>();

        //if(CollectionUtils.isNotEmpty(stationMap) && CollectionUtils.isNotEmpty(listSingleStations) ){  //有可能有的车站没有数据
		if(CollectionUtils.isNotEmpty(stationMap)){
			//车站循环,每个车站只有一个合计
			for (Map<String,String> mapStations : stationMap) {
				 String stationCode = mapStations.get("CODE");
				 String stationName = mapStations.get("NAME");

				 SwCkDailyTicketIncomeExportDTO swCkSingleStationSum = new SwCkDailyTicketIncomeExportDTO();
				 
				 List<SwCkDailyTicketIncomeExportDTO> records  = new ArrayList<>();

				 if(CollectionUtils.isNotEmpty(listSingleStations)){
					  //按车站分组，过滤出对应车站的数据
					 List<SwCkDailyTicketIncomeExportDTO> collect = listSingleStations.stream().filter(x -> stationCode.equals(x.getStationCode())).collect(Collectors.toList());
					 
					 for(SwCkDailyTicketIncomeExportDTO obj : collect) {
							adjustIncomeForm(obj,swCkSingleStationSum,false);//求合计值
							records.add(obj);
						}
				 }				
				 records.add(swCkSingleStationSum);//将合计追加到最后一条				 
				 map.put(stationName,records);//这样保证，即使有的车站没数据也不会报错
				 mapLocalName.put(stationName,stationName);//显示车站名称
				 
             }
			InputStream excelTemplateIs = null;
            try {
				response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
				String tmpFileName = "-日票售卖统计表-按收益-";
                final String fileName = URLEncoder.encode(tmpFileName, "UTF-8");
                response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

                // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                // {} 代表普通变量 {.} 代表是list的变量

                excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkDailyTicketSaleByIncomeExcelTemplate.xlsx");

                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

                //1. 每个车站的导出
				int i=0;//计数器，创建了多少个Sheet
				for (Map.Entry<String, List<SwCkDailyTicketIncomeExportDTO>> integerListEntry : map.entrySet()) {
                    i++;
					String key = integerListEntry.getKey();//存的是车站名字
                    List<SwCkDailyTicketIncomeExportDTO> value = integerListEntry.getValue();
                    // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                    // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                    // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                    // 如果数据量大 list不是最后一行 参照另一个
                    //WriteSheet writeSheet = EasyExcel.writerSheet(key-1,String.valueOf(key)).build();
					
					WriteSheet writeSheet = EasyExcel.writerSheet(i-1,key).build();
                    FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(value, fillConfig, writeSheet);
                    Map<String, Object> mapDate = new HashMap<>();
                    mapDate.put("stationName", mapLocalName.get(key));                  
                    excelWriter.fill(mapDate,writeSheet);
                }
                //车站和日期合计，填写日期 
				Map<String, Object> mapOther = new HashMap<>();
                //mapOther.put("lineName",lineName);
				mapOther.put("startDate",startDate);
				mapOther.put("endDate",endDate);

				log.error("车站循环最后的序号====i==="+i);

				//2. 日期合计(有pos机明细)
				//if(CollectionUtil.isNotEmpty(listDay)){
                    List<SwCkDailyTicketIncomeExportDTO> recordsSinglePosDay  = new ArrayList<>();
					SwCkDailyTicketIncomeExportDTO swCkSinglePosStationSum = new SwCkDailyTicketIncomeExportDTO();	
                    if(CollectionUtil.isNotEmpty(listSinglePosDay)){
						for(SwCkDailyTicketIncomeExportDTO obj : listSinglePosDay) {  
							adjustIncomeForm(obj,swCkSinglePosStationSum,true);//求合计值
							recordsSinglePosDay.add(obj);
						}
					}
					 recordsSinglePosDay.add(swCkSinglePosStationSum);//将合计追加到最后一条	

                    //必须加上sheetNo,否则会追加
                    WriteSheet writeSheetSinglePosDay = EasyExcel.writerSheet(i,"日期合计(有pos机明细)").build();
                    FillConfig fillConfigSinglePosDay = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(recordsSinglePosDay, fillConfigSinglePosDay, writeSheetSinglePosDay);
                    excelWriter.fill(mapOther, writeSheetSinglePosDay);
                //}

                //3. 车站合计
                //if(CollectionUtil.isNotEmpty(listStationTotal)){
                    List<SwCkDailyTicketIncomeExportDTO> recordsStationTotal  = new ArrayList<>();
					SwCkDailyTicketIncomeExportDTO swCkSingleStationSum2 = new SwCkDailyTicketIncomeExportDTO();	
                    if(CollectionUtil.isNotEmpty(listStationTotal)){
						for(SwCkDailyTicketIncomeExportDTO obj : listStationTotal) {                        			
							adjustIncomeForm(obj,swCkSingleStationSum2,true);//求合计值
							recordsStationTotal.add(obj);
						}
					}
					recordsStationTotal.add(swCkSingleStationSum2);//将合计追加到最后一条	
                    //必须加上sheetNo,否则会追加
                    WriteSheet writeSheetStationAll = EasyExcel.writerSheet(i+1,"车站合计").build();
                    FillConfig fillConfigStationAll = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(recordsStationTotal, fillConfigStationAll, writeSheetStationAll);

                    excelWriter.fill(mapOther, writeSheetStationAll);
                //}
				//4. 日期合计(pos机合并)
				//if(CollectionUtil.isNotEmpty(listDay)){
                   
					List<SwCkDailyTicketIncomeExportDTO> recordsDay  = new ArrayList<>();
					SwCkDailyTicketIncomeExportDTO swCkSingleStationSum = new SwCkDailyTicketIncomeExportDTO();	
                    if(CollectionUtil.isNotEmpty(listDay)){
						for(SwCkDailyTicketIncomeExportDTO obj : listDay) {  
							adjustIncomeForm(obj,swCkSingleStationSum,true);//求合计值
							recordsDay.add(obj);
						}
					}
					 recordsDay.add(swCkSingleStationSum);//将合计追加到最后一条	
                    
                    //必须加上sheetNo,否则会追加
                    WriteSheet writeSheetDayPos = EasyExcel.writerSheet(i+2,"日期合计(pos机合至现金)").build();
                    FillConfig fillConfigDayPos = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(recordsDay, fillConfigDayPos, writeSheetDayPos);
                    excelWriter.fill(mapOther, writeSheetDayPos);
                //}

				

				//最后完成
                excelWriter.finish();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("导出日票售卖统计表按收益导出错误");
            } finally {
                if(excelTemplateIs != null){
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }

                }
            }

			

        }
	
	}

    @Override
    public void exportDataTicketCardByResultExport(String startDate, String endDate, HttpServletResponse response) {
        InputStream excelTemplateIs = null;
        try {
            List<SwCkDailyTicketIncomeExportDTO> lstResultTemp = new ArrayList<>();

            List<String> listDate = MyDateUtil.getDatesBetweenTwoDate(startDate,endDate);
            List<ListDataLogDTO> listDataLog = this.baseMapper.getDataLog(startDate, endDate);

            //电子的
            List<SwCkDailyTicketIncomeExportDTO> lstResultTempDTOList = this.baseMapper.getOnlinePayment(startDate, endDate);
            for (SwCkDailyTicketIncomeExportDTO onlinePaymentDTO : lstResultTempDTOList) {
                SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO = new SwCkDailyTicketIncomeExportDTO();
                swCkDailyTicketIncomeExportDTO.setTradeDateTostring(onlinePaymentDTO.getTradeDateTostring());
//                swCkDailyTicketIncomeExportDTO.setTicketTypeEn(onlinePaymentDTO.getTicketTypeEn());

                swCkDailyTicketIncomeExportDTO.setAlipySaleNumYrp(onlinePaymentDTO.getAlipySaleNumYrp());
                swCkDailyTicketIncomeExportDTO.setAlipySaleAmountYrp(onlinePaymentDTO.getAlipySaleAmountYrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleNumYrp(onlinePaymentDTO.getWechatSaleNumYrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountYrp(onlinePaymentDTO.getWechatSaleAmountYrp());
				swCkDailyTicketIncomeExportDTO.setPosSaleNumYrp(onlinePaymentDTO.getPosSaleNumYrp());
                swCkDailyTicketIncomeExportDTO.setPosSaleAmountYrp(onlinePaymentDTO.getPosSaleAmountYrp());
                
				swCkDailyTicketIncomeExportDTO.setAlipySaleNumSrp(onlinePaymentDTO.getAlipySaleNumSrp());
                swCkDailyTicketIncomeExportDTO.setAlipySaleAmountSrp(onlinePaymentDTO.getAlipySaleAmountSrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleNumSrp(onlinePaymentDTO.getWechatSaleNumSrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountSrp(onlinePaymentDTO.getWechatSaleAmountSrp());
				swCkDailyTicketIncomeExportDTO.setPosSaleNumSrp(onlinePaymentDTO.getPosSaleNumSrp());
                swCkDailyTicketIncomeExportDTO.setPosSaleAmountSrp(onlinePaymentDTO.getPosSaleAmountSrp());

                
				swCkDailyTicketIncomeExportDTO.setAlipySaleNumZlljsrp(onlinePaymentDTO.getAlipySaleNumZlljsrp());
                swCkDailyTicketIncomeExportDTO.setAlipySaleAmountZlljsrp(onlinePaymentDTO.getAlipySaleAmountZlljsrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleNumZlljsrp(onlinePaymentDTO.getWechatSaleNumZlljsrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountZlljsrp(onlinePaymentDTO.getWechatSaleAmountZlljsrp());				
				swCkDailyTicketIncomeExportDTO.setPosSaleNumZlljsrp(onlinePaymentDTO.getPosSaleNumZlljsrp());
                swCkDailyTicketIncomeExportDTO.setPosSaleAmountZlljsrp(onlinePaymentDTO.getPosSaleAmountZlljsrp());

                lstResultTemp.add(swCkDailyTicketIncomeExportDTO);
            }

            List<SwCkDailyTicketIncomeExportDTO> cashListTemp = new ArrayList<>();
            for (ListDataLogDTO listDataLogDTO : listDataLog) {
                List<SwCkDailyTicketIncomeExportDTO> cashEntityDTOList = this.baseMapper.getCashEntity(listDataLogDTO);
                for (SwCkDailyTicketIncomeExportDTO cashEntityDTO : cashEntityDTOList) {
                    SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO = new SwCkDailyTicketIncomeExportDTO();
                    swCkDailyTicketIncomeExportDTO.setTradeDateTostring(cashEntityDTO.getTradeDateTostring());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumYrp(cashEntityDTO.getCashSaleNumYrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountYrp(cashEntityDTO.getCashSaleAmountYrp());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumSrp(cashEntityDTO.getCashSaleNumSrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountSrp(cashEntityDTO.getCashSaleAmountSrp());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumZlljsrp(cashEntityDTO.getCashSaleNumZlljsrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountZlljsrp(cashEntityDTO.getCashSaleAmountZlljsrp());

                    cashListTemp.add(swCkDailyTicketIncomeExportDTO);
                }
            }
            log.info("cashListTemp--------->输出：{}", cashListTemp);
            Map<String, SwCkDailyTicketIncomeExportDTO> exportDTOMap = new LinkedHashMap<>();
            for (String strDate : listDate) {
                for (SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO :lstResultTemp) {
                    if (strDate.equals(swCkDailyTicketIncomeExportDTO.getTradeDateTostring())) {
                        exportDTOMap.put(strDate, swCkDailyTicketIncomeExportDTO);
                    }
                }

                for (SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO :cashListTemp){
                    if (strDate.equals(swCkDailyTicketIncomeExportDTO.getTradeDateTostring())){
                        if(exportDTOMap.containsKey(strDate)){
							SwCkDailyTicketIncomeExportDTO haveDto = exportDTOMap.get(strDate);
							haveDto.setCashSaleNumYrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumYrp());
							haveDto.setCashSaleAmountYrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountYrp());
							haveDto.setCashSaleNumSrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumSrp());
							haveDto.setCashSaleAmountSrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountSrp());
							haveDto.setCashSaleNumZlljsrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumZlljsrp());
							haveDto.setCashSaleAmountZlljsrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountZlljsrp());
							
							exportDTOMap.put(strDate, haveDto);
                        }else{
							 exportDTOMap.put(strDate, swCkDailyTicketIncomeExportDTO);
                        }
                       
                    }
                }

                if (!exportDTOMap.containsKey(strDate)) {
                    SwCkDailyTicketIncomeExportDTO exportDTO = new SwCkDailyTicketIncomeExportDTO();
                    exportDTO.setTradeDateTostring(strDate);
                    exportDTOMap.put(strDate, exportDTO);
                }
                log.info("exportDTOMap:输出===》:{}", exportDTOMap);
            }
            List<SwCkDailyTicketIncomeExportDTO> exportDTOS = new ArrayList<>();

            for (Map.Entry<String, SwCkDailyTicketIncomeExportDTO> entry : exportDTOMap.entrySet()) {
                SwCkDailyTicketIncomeExportDTO exportDTO = entry.getValue();
                exportDTO.setSubSaleNumYrp(
                        exportDTO.getCashSaleNumYrp() + exportDTO.getAlipySaleNumYrp() + exportDTO.getWechatSaleNumYrp()+ exportDTO.getPosSaleNumYrp()
                );
                exportDTO.setSubSaleAmountYrp(
                        exportDTO.getCashSaleAmountYrp().add(exportDTO.getAlipySaleAmountYrp()).add(exportDTO.getWechatSaleAmountYrp()).add(exportDTO.getPosSaleAmountYrp())
                );
                exportDTO.setSubSaleNumSrp(
                        exportDTO.getCashSaleNumSrp() + exportDTO.getAlipySaleNumSrp() + exportDTO.getWechatSaleNumSrp()+ exportDTO.getPosSaleNumSrp()
                );
                exportDTO.setSubSaleAmountSrp(
                        exportDTO.getCashSaleAmountSrp().add(exportDTO.getAlipySaleAmountSrp()).add(exportDTO.getWechatSaleAmountSrp()).add(exportDTO.getPosSaleAmountSrp())
                );
                exportDTO.setSubSaleNumZlljsrp(
                        exportDTO.getCashSaleNumZlljsrp() + exportDTO.getAlipySaleNumZlljsrp() + exportDTO.getWechatSaleNumZlljsrp()+ exportDTO.getPosSaleNumZlljsrp()
                );
                exportDTO.setSubSaleAmountZlljsrp(
                        exportDTO.getCashSaleAmountZlljsrp().add(exportDTO.getAlipySaleAmountZlljsrp()).add(exportDTO.getWechatSaleAmountZlljsrp()).add(exportDTO.getPosSaleAmountZlljsrp())
                );
                exportDTO.setCashSaleNumPay(
                        exportDTO.getCashSaleNumYrp() + exportDTO.getCashSaleNumSrp() + exportDTO.getCashSaleNumZlljsrp()
                );
                exportDTO.setCashSaleAmountPay(
                        exportDTO.getCashSaleAmountYrp().add(exportDTO.getCashSaleAmountSrp()).add(exportDTO.getCashSaleAmountZlljsrp())
                );
                exportDTO.setAlipySaleNumPay(
                        exportDTO.getAlipySaleNumYrp() + exportDTO.getAlipySaleNumSrp() + exportDTO.getAlipySaleNumZlljsrp()
                );
                exportDTO.setAlipySaleAmountPay(
                        exportDTO.getAlipySaleAmountYrp().add(exportDTO.getAlipySaleAmountSrp()).add(exportDTO.getAlipySaleAmountZlljsrp())
                );
                exportDTO.setWechatSaleNumPay(
                        exportDTO.getWechatSaleNumYrp() + exportDTO.getWechatSaleNumSrp() + exportDTO.getWechatSaleNumZlljsrp()
                );
                exportDTO.setWechatSaleAmountPay(
                        exportDTO.getWechatSaleAmountYrp().add(exportDTO.getWechatSaleAmountSrp()).add(exportDTO.getWechatSaleAmountZlljsrp())
                );
				exportDTO.setPosSaleNumPay(
                        exportDTO.getPosSaleNumYrp() + exportDTO.getPosSaleNumSrp() + exportDTO.getPosSaleNumZlljsrp()
                );
                exportDTO.setPosSaleAmountPay(
                        exportDTO.getPosSaleAmountYrp().add(exportDTO.getPosSaleAmountSrp()).add(exportDTO.getPosSaleAmountZlljsrp())
                );
                exportDTO.setSaleNum(
                        exportDTO.getCashSaleNumPay() + exportDTO.getAlipySaleNumPay() + exportDTO.getWechatSaleNumPay()+ exportDTO.getPosSaleNumPay()
                );
                exportDTO.setSaleAmount(
                        exportDTO.getCashSaleAmountPay().add(exportDTO.getAlipySaleAmountPay()).add(exportDTO.getWechatSaleAmountPay()).add(exportDTO.getPosSaleAmountPay())
                );
                exportDTOS.add(exportDTO);
            }
            SwCkDailyTicketIncomeExportDTO total = new SwCkDailyTicketIncomeExportDTO();
            total.setTradeDateTostring("合计");
            total.setCashSaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getCashSaleNumYrp).sum()
            );
            total.setCashSaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getCashSaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setAlipySaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getAlipySaleNumYrp).sum()
            );
            total.setAlipySaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getAlipySaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setWechatSaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getWechatSaleNumYrp).sum()
            );
            total.setWechatSaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getWechatSaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setPosSaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getPosSaleNumYrp).sum()
            );
            total.setPosSaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getPosSaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setSubSaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumYrp).sum()
            );
            total.setSubSaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setCashSaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getCashSaleNumSrp).sum()
            );
            total.setCashSaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getCashSaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setAlipySaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getAlipySaleNumSrp).sum()
            );
            total.setAlipySaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getAlipySaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setWechatSaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getWechatSaleNumSrp).sum()
            );
            total.setWechatSaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getWechatSaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setPosSaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getPosSaleNumSrp).sum()
            );
            total.setPosSaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getPosSaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setSubSaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumSrp).sum()
            );
            total.setSubSaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setCashSaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getCashSaleNumZlljsrp).sum()
            );
            total.setCashSaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getCashSaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setAlipySaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getAlipySaleNumZlljsrp).sum()
            );
            total.setAlipySaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getAlipySaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setWechatSaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getWechatSaleNumZlljsrp).sum()
            );
            total.setWechatSaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getWechatSaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setPosSaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getPosSaleNumZlljsrp).sum()
            );
            total.setPosSaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getPosSaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setSubSaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumZlljsrp).sum()
            );
            total.setSubSaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setCashSaleNumPay(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getCashSaleNumPay).sum()
            );
            total.setCashSaleAmountPay(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getCashSaleAmountPay).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setAlipySaleNumPay(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getAlipySaleNumPay).sum()
            );
            total.setAlipySaleAmountPay(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getAlipySaleAmountPay).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setWechatSaleNumPay(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getWechatSaleNumPay).sum()
            );
            total.setWechatSaleAmountPay(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getWechatSaleAmountPay).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setPosSaleNumPay(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getPosSaleNumPay).sum()
            );
            total.setPosSaleAmountPay(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getPosSaleAmountPay).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
            total.setSaleNum(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSaleNum).sum()
            );
            total.setSaleAmount(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSaleAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
            );

            exportDTOS.add(total);
            log.info("exportDTOS:输出======》:{}", exportDTOS);


            response.reset(); // 非常重要
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            String tmpFileName = "-日票售卖统计表-按结果-";
            final String fileName = URLEncoder.encode(tmpFileName, "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

            excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkDailyTicketSaleByResultExcelTemplate.xlsx");


            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

            WriteSheet writeSheet = EasyExcel.writerSheet("收益合计").build();

            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            excelWriter.fill(exportDTOS, fillConfig, writeSheet);


            //最后完成
            excelWriter.finish();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("按结果导出日票售卖导出错误");
        } finally {
            if(excelTemplateIs != null){
                try {
                    excelTemplateIs.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }

            }
        }
    }
	//日票对账确认表
	@Override
    public void exportDataTicketCardByCheck(String startDate, String endDate, HttpServletResponse response){

		InputStream excelTemplateIs = null;
        try {
            List<SwCkDailyTicketIncomeExportDTO> lstResultTemp = new ArrayList<>();

            List<String> listDate = MyDateUtil.getDatesBetweenTwoDate(startDate,endDate);
            List<ListDataLogDTO> listDataLog = this.baseMapper.getDataLog(startDate, endDate);
            //表头
            Map<String,Object> mapRcaHead = this.baseMapper.getDailyTicketSaleByRcaHead(startDate, endDate);
			
			SwCkDailyTicketSaleExportDTO swCkSingleStationSum = new SwCkDailyTicketSaleExportDTO();
			if(mapRcaHead!=null && mapRcaHead.size()>0){
				//本月替换数量			
				int ticketReplaceYrp  = Integer.parseInt(String.valueOf(mapRcaHead.get("TICKET_REPLACE_YRP")));
				swCkSingleStationSum.setTicketReplaceYrp(ticketReplaceYrp);
				
				int ticketReplaceSrp  = Integer.parseInt(String.valueOf(mapRcaHead.get("TICKET_REPLACE_SRP")));
				swCkSingleStationSum.setTicketReplaceSrp(ticketReplaceSrp);

				int ticketReplaceZlljsrp  =Integer.parseInt(String.valueOf(mapRcaHead.get("TICKET_REPLACE_ZLLJSRP")));
				swCkSingleStationSum.setTicketReplaceZlljsrp(ticketReplaceZlljsrp);
				//配送数量--本月领取数量
				int distributionStationYrp  =Integer.parseInt(String.valueOf(mapRcaHead.get("DISTRIBUTION_STATION_YRP")));
				swCkSingleStationSum.setDistributionStationYrp(distributionStationYrp);
				
				int distributionStationSrp  =Integer.parseInt(String.valueOf(mapRcaHead.get("DISTRIBUTION_STATION_SRP")));
				swCkSingleStationSum.setDistributionStationSrp(distributionStationSrp);

				int distributionStationZlljsrp  =Integer.parseInt(String.valueOf(mapRcaHead.get("DISTRIBUTION_STATION_ZLLJSRP")));
				swCkSingleStationSum.setDistributionStationZlljsrp(distributionStationZlljsrp);
				//本月售卖数量后面根据明细获取合计值再赋值---todo

			}
            //明细--电子的s售卖数量和金额，借用wechat变量
            List<SwCkDailyTicketIncomeExportDTO> lstResultTempDTOList = this.baseMapper.getRcaDetailPayment(startDate, endDate);
            for (SwCkDailyTicketIncomeExportDTO onlinePaymentDTO : lstResultTempDTOList) {
                SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO = new SwCkDailyTicketIncomeExportDTO();
                swCkDailyTicketIncomeExportDTO.setTradeDateTostring(onlinePaymentDTO.getTradeDateTostring());
//                swCkDailyTicketIncomeExportDTO.setTicketTypeEn(onlinePaymentDTO.getTicketTypeEn());

                swCkDailyTicketIncomeExportDTO.setWechatSaleNumYrp(onlinePaymentDTO.getWechatSaleNumYrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountYrp(onlinePaymentDTO.getWechatSaleAmountYrp());

				swCkDailyTicketIncomeExportDTO.setWechatSaleNumSrp(onlinePaymentDTO.getWechatSaleNumSrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountSrp(onlinePaymentDTO.getWechatSaleAmountSrp());

				swCkDailyTicketIncomeExportDTO.setWechatSaleNumZlljsrp(onlinePaymentDTO.getWechatSaleNumZlljsrp());
                swCkDailyTicketIncomeExportDTO.setWechatSaleAmountZlljsrp(onlinePaymentDTO.getWechatSaleAmountZlljsrp());
                lstResultTemp.add(swCkDailyTicketIncomeExportDTO);
            }
            //现金的数量和金额
            List<SwCkDailyTicketIncomeExportDTO> cashListTemp = new ArrayList<>();
            for (ListDataLogDTO listDataLogDTO : listDataLog) {
                List<SwCkDailyTicketIncomeExportDTO> cashEntityDTOList = this.baseMapper.getCashEntity(listDataLogDTO);
                for (SwCkDailyTicketIncomeExportDTO cashEntityDTO : cashEntityDTOList) {
                    SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO = new SwCkDailyTicketIncomeExportDTO();
                    swCkDailyTicketIncomeExportDTO.setTradeDateTostring(cashEntityDTO.getTradeDateTostring());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumYrp(cashEntityDTO.getCashSaleNumYrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountYrp(cashEntityDTO.getCashSaleAmountYrp());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumSrp(cashEntityDTO.getCashSaleNumSrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountSrp(cashEntityDTO.getCashSaleAmountSrp());

                    swCkDailyTicketIncomeExportDTO.setCashSaleNumZlljsrp(cashEntityDTO.getCashSaleNumZlljsrp());
                    swCkDailyTicketIncomeExportDTO.setCashSaleAmountZlljsrp(cashEntityDTO.getCashSaleAmountZlljsrp());

                    cashListTemp.add(swCkDailyTicketIncomeExportDTO);
                }
            }
            log.info("cashListTemp--------->输出：{}", cashListTemp);
            Map<String, SwCkDailyTicketIncomeExportDTO> exportDTOMap = new LinkedHashMap<>();
            for (String strDate : listDate) {
                for (SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO :lstResultTemp) {
                    if (strDate.equals(swCkDailyTicketIncomeExportDTO.getTradeDateTostring())) {
                        exportDTOMap.put(strDate, swCkDailyTicketIncomeExportDTO);
                    }
                }

                for (SwCkDailyTicketIncomeExportDTO swCkDailyTicketIncomeExportDTO :cashListTemp){
                    if (strDate.equals(swCkDailyTicketIncomeExportDTO.getTradeDateTostring())){
                        if(exportDTOMap.containsKey(strDate)){
							SwCkDailyTicketIncomeExportDTO haveDto = exportDTOMap.get(strDate);
							haveDto.setCashSaleNumYrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumYrp());
							haveDto.setCashSaleAmountYrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountYrp());
							haveDto.setCashSaleNumSrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumSrp());
							haveDto.setCashSaleAmountSrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountSrp());
							haveDto.setCashSaleNumZlljsrp(swCkDailyTicketIncomeExportDTO.getCashSaleNumZlljsrp());
							haveDto.setCashSaleAmountZlljsrp(swCkDailyTicketIncomeExportDTO.getCashSaleAmountZlljsrp());
							
							exportDTOMap.put(strDate, haveDto);
                        }else{
							 exportDTOMap.put(strDate, swCkDailyTicketIncomeExportDTO);
                        }
                       
                    }
                }

                if (!exportDTOMap.containsKey(strDate)) {
                    SwCkDailyTicketIncomeExportDTO exportDTO = new SwCkDailyTicketIncomeExportDTO();
                    exportDTO.setTradeDateTostring(strDate);
                    exportDTOMap.put(strDate, exportDTO);
                }
                log.info("exportDTOMap:输出===》:{}", exportDTOMap);
            }
            List<SwCkDailyTicketIncomeExportDTO> exportDTOS = new ArrayList<>();
            //每天的售卖数量现金和电子的合计 以及行合计
            for (Map.Entry<String, SwCkDailyTicketIncomeExportDTO> entry : exportDTOMap.entrySet()) {
                SwCkDailyTicketIncomeExportDTO exportDTO = entry.getValue();
                exportDTO.setSubSaleNumYrp(
                        exportDTO.getCashSaleNumYrp() + exportDTO.getWechatSaleNumYrp() 
                );
                exportDTO.setSubSaleAmountYrp(
                        exportDTO.getCashSaleAmountYrp().add(exportDTO.getWechatSaleAmountYrp())
                );
                exportDTO.setSubSaleNumSrp(
                        exportDTO.getCashSaleNumSrp() + exportDTO.getWechatSaleNumSrp()
                );
                exportDTO.setSubSaleAmountSrp(
                        exportDTO.getCashSaleAmountSrp().add(exportDTO.getWechatSaleAmountSrp())
                );
                exportDTO.setSubSaleNumZlljsrp(
                        exportDTO.getCashSaleNumZlljsrp()  + exportDTO.getWechatSaleNumZlljsrp()
                );
                exportDTO.setSubSaleAmountZlljsrp(
                        exportDTO.getCashSaleAmountZlljsrp().add(exportDTO.getWechatSaleAmountZlljsrp())
                );
				//一日票剩余库存数量借用 posSaleNumPay  三日票alipySaleNumPay  昭陵六骏三日票wechatSaleNumPay
                exportDTO.setPosSaleNumPay(0);
				exportDTO.setAlipySaleNumPay(0);
				exportDTO.setWechatSaleNumPay(0);
				//行合计剩余库存数量借用  cashSaleNumPay
				exportDTO.setCashSaleNumPay(0);


                //行合计
                exportDTO.setSaleNum(
                        exportDTO.getSubSaleNumYrp() + exportDTO.getSubSaleNumSrp() + exportDTO.getSubSaleNumZlljsrp()
                );
                exportDTO.setSaleAmount(
                        exportDTO.getSubSaleAmountYrp().add(exportDTO.getSubSaleAmountSrp()).add(exportDTO.getSubSaleAmountZlljsrp())
                );
                exportDTOS.add(exportDTO);
            }
			//列合计
            SwCkDailyTicketIncomeExportDTO total = new SwCkDailyTicketIncomeExportDTO();
            total.setTradeDateTostring("合计");
            //
			total.setSubSaleNumYrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumYrp).sum()
            );
            total.setSubSaleAmountYrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountYrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setSubSaleNumSrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumSrp).sum()
            );
            total.setSubSaleAmountSrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountSrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setSubSaleNumZlljsrp(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSubSaleNumZlljsrp).sum()
            );
            total.setSubSaleAmountZlljsrp(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSubSaleAmountZlljsrp).reduce(BigDecimal.ZERO, BigDecimal::add)
            );
			total.setPosSaleNumPay(
			         exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getPosSaleNumPay).sum()	
		    );
			total.setAlipySaleNumPay(
			         exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getAlipySaleNumPay).sum()	
		    );
			total.setWechatSaleNumPay(
			         exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getWechatSaleNumPay).sum()	
		    );
			total.setCashSaleNumPay(
			         exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getCashSaleNumPay).sum()	
		    );			
			total.setSaleNum(
                    exportDTOS.stream().mapToInt(SwCkDailyTicketIncomeExportDTO::getSaleNum).sum()
            );
            total.setSaleAmount(
                    exportDTOS.stream().map(SwCkDailyTicketIncomeExportDTO::getSaleAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
            );  
			//设置表头中的本月售卖数量,借用BalanceToday属性
			swCkSingleStationSum.setBalanceTodayYrp(total.getSubSaleNumYrp());
			swCkSingleStationSum.setBalanceTodaySrp(total.getSubSaleNumSrp());
			swCkSingleStationSum.setBalanceTodayZlljsrp(total.getSubSaleNumZlljsrp());

            exportDTOS.add(total);
            log.info("exportDTOS:输出======》:{}", exportDTOS);


            response.reset(); // 非常重要
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            String tmpFileName = "-日票代售对账确认表-";
            final String fileName = URLEncoder.encode(tmpFileName, "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + startDate +"~"+endDate + fileName + MyDateUtil.getNowDayString("yyyy-MM-dd") + ".xlsx");

            excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkDailyTicketSaleByRcaExcelTemplate.xlsx");


            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

            WriteSheet writeSheet = EasyExcel.writerSheet("汇总表").build();

            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            excelWriter.fill(exportDTOS, fillConfig, writeSheet);
		    //其他单独属性
			Map<String, Object> mapOther = new HashMap<>();
         	mapOther.put("startDate",startDate);
			mapOther.put("endDate",endDate);
			String currentDate = MyDateUtil.getNowDayString("yyyy年MM月dd日");//需要获取当前日期 --todo 
			mapOther.put("currDate",currentDate);
			mapOther.put("distributionStationYrp",swCkSingleStationSum.getDistributionStationYrp());//本月领取
			mapOther.put("distributionStationSrp",swCkSingleStationSum.getDistributionStationSrp());//本月领取
			mapOther.put("distributionStationZlljsrp",swCkSingleStationSum.getDistributionStationZlljsrp());//本月领取
			mapOther.put("ticketReplaceYrp",swCkSingleStationSum.getTicketReplaceYrp());//本月替换
			mapOther.put("ticketReplaceSrp",swCkSingleStationSum.getTicketReplaceSrp());
			mapOther.put("ticketReplaceZlljsrp",swCkSingleStationSum.getTicketReplaceZlljsrp());
			mapOther.put("balanceTodayYrp",swCkSingleStationSum.getBalanceTodayYrp()); //本月售卖
			mapOther.put("balanceTodaySrp",swCkSingleStationSum.getBalanceTodaySrp()); //本月售卖
			mapOther.put("balanceTodayZlljsrp",swCkSingleStationSum.getBalanceTodayZlljsrp()); //本月售卖
			
			//mapOther.put("rcaHead",swCkSingleStationSum);//该属性要拆开---todo
		    excelWriter.fill(mapOther, writeSheet);

            //最后完成
            excelWriter.finish();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("日票代售对账确认表导出错误");
        } finally {
            if(excelTemplateIs != null){
                try {
                    excelTemplateIs.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }

            }
        }
		

    }

    /**
	  按票卡统计--计算合计值
	  obj:  某一日的数据
      swCkSingleStationSum: 车站合计
	*/
	private void adjustForm(SwCkDailyTicketSaleExportDTO obj,SwCkDailyTicketSaleExportDTO swCkSingleStationSum,boolean isStatOther){
            
		swCkSingleStationSum.setStationName("合计");
		swCkSingleStationSum.setTradeDateTostring("合计");
		boolean isExist = false;
		if(swCkSingleStationSum!=null && swCkSingleStationSum.getBalanceLastdayYrp()!=null){
			isExist = true;
		}
		//本日结存
		int balanceLastdayYrp  = 0;	
		
		if(isExist){
			balanceLastdayYrp = swCkSingleStationSum.getBalanceLastdayYrp();
		}
		swCkSingleStationSum.setBalanceLastdayYrp(balanceLastdayYrp+obj.getBalanceLastdayYrp());
		
		int balanceLastdaySrp  = 0;
		if(isExist){
			balanceLastdaySrp = swCkSingleStationSum.getBalanceLastdaySrp();
		}
		
		swCkSingleStationSum.setBalanceLastdaySrp(balanceLastdaySrp+obj.getBalanceLastdaySrp());

		int balanceLastdayZlljsrp  = 0;
		if(isExist){
		   balanceLastdayZlljsrp = swCkSingleStationSum.getBalanceLastdayZlljsrp();
		}
		swCkSingleStationSum.setBalanceLastdayZlljsrp(balanceLastdayZlljsrp+obj.getBalanceLastdayZlljsrp());
        
		//售卖数量
		int boxOfficeSaleYrp  = 0;
		if(isExist){
		   boxOfficeSaleYrp =  swCkSingleStationSum.getBoxOfficeSaleYrp();
		}		
		swCkSingleStationSum.setBoxOfficeSaleYrp(boxOfficeSaleYrp+obj.getBoxOfficeSaleYrp());
		
		int boxOfficeSaleSrp  = 0;
		if(isExist){
		    boxOfficeSaleSrp =  swCkSingleStationSum.getBoxOfficeSaleSrp();
		}		
		swCkSingleStationSum.setBoxOfficeSaleSrp(boxOfficeSaleSrp+obj.getBoxOfficeSaleSrp());

		int boxOfficeSaleZlljsrp =  0;
		if(isExist){
		    boxOfficeSaleZlljsrp = swCkSingleStationSum.getBoxOfficeSaleZlljsrp();
		}
		swCkSingleStationSum.setBoxOfficeSaleZlljsrp(boxOfficeSaleZlljsrp+obj.getBoxOfficeSaleZlljsrp());
        //替换数量
		
		int ticketReplaceYrp = 0;
		if(isExist){
		   ticketReplaceYrp = swCkSingleStationSum.getTicketReplaceYrp();
		}
		swCkSingleStationSum.setTicketReplaceYrp(ticketReplaceYrp+obj.getTicketReplaceYrp());
		
		int ticketReplaceSrp  = 0;
		if(isExist){
		   ticketReplaceSrp = swCkSingleStationSum.getTicketReplaceSrp();
		}
		swCkSingleStationSum.setTicketReplaceSrp(ticketReplaceSrp+obj.getTicketReplaceSrp());

		int ticketReplaceZlljsrp = 0;
		if(isExist){
			
            ticketReplaceZlljsrp = swCkSingleStationSum.getTicketReplaceZlljsrp();
		}
		swCkSingleStationSum.setTicketReplaceZlljsrp(ticketReplaceZlljsrp+obj.getTicketReplaceZlljsrp());

		 //上交数量
		
		int ticketHandYrp = 0;
		if(isExist){
		   ticketHandYrp = swCkSingleStationSum.getTicketHandYrp();
		}
		swCkSingleStationSum.setTicketHandYrp(ticketHandYrp+obj.getTicketHandYrp());
		
		int ticketHandSrp  = 0;
		if(isExist){
		   ticketHandSrp = swCkSingleStationSum.getTicketHandSrp();
		}
		swCkSingleStationSum.setTicketHandSrp(ticketHandSrp+obj.getTicketHandSrp());

		int ticketHandZlljsrp = 0;
		if(isExist){
			
            ticketHandZlljsrp = swCkSingleStationSum.getTicketHandZlljsrp();
		}
		swCkSingleStationSum.setTicketHandZlljsrp(ticketHandZlljsrp+obj.getTicketHandZlljsrp());

		 //人工回收数量
		
		int ticketRecycleYrp = 0;
		if(isExist){
		   ticketRecycleYrp = swCkSingleStationSum.getTicketRecycleYrp();
		}
		swCkSingleStationSum.setTicketRecycleYrp(ticketRecycleYrp+obj.getTicketRecycleYrp());
		
		int ticketRecycleSrp  = 0;
		if(isExist){
		   ticketRecycleSrp = swCkSingleStationSum.getTicketRecycleSrp();
		}
		swCkSingleStationSum.setTicketRecycleSrp(ticketRecycleSrp+obj.getTicketRecycleSrp());

		int ticketRecycleZlljsrp = 0;
		if(isExist){
			
            ticketRecycleZlljsrp = swCkSingleStationSum.getTicketRecycleZlljsrp();
		}
		swCkSingleStationSum.setTicketRecycleZlljsrp(ticketRecycleZlljsrp+obj.getTicketRecycleZlljsrp());
        //配送数量
		int distributionStationYrp  = 0;
		if(isExist){
		  distributionStationYrp  = swCkSingleStationSum.getDistributionStationYrp();
		}
		swCkSingleStationSum.setDistributionStationYrp(distributionStationYrp+obj.getDistributionStationYrp());
		
		int distributionStationSrp  = 0;
		if(isExist){
		    distributionStationSrp = swCkSingleStationSum.getDistributionStationSrp();
		}
		swCkSingleStationSum.setDistributionStationSrp(distributionStationSrp+obj.getDistributionStationSrp());

		int distributionStationZlljsrp =   0;
		if(isExist){
		  distributionStationZlljsrp = swCkSingleStationSum.getDistributionStationZlljsrp();
		}
		swCkSingleStationSum.setDistributionStationZlljsrp(distributionStationZlljsrp+obj.getDistributionStationZlljsrp());
        //调票数量
		int transferStationYrp  = 0;
		if(isExist){
		   transferStationYrp  = swCkSingleStationSum.getTransferStationYrp();
		}
		swCkSingleStationSum.setTransferStationYrp(transferStationYrp+obj.getTransferStationYrp());
		
		int transferStationSrp  = 0;
		if(isExist){
		   transferStationSrp = swCkSingleStationSum.getTransferStationSrp();
		}
		swCkSingleStationSum.setTransferStationSrp(transferStationSrp+obj.getTransferStationSrp());

		int transferStationZlljsrp  = 0;
		if(isExist){
		   transferStationZlljsrp  = swCkSingleStationSum.getTransferStationZlljsrp();
		}
		swCkSingleStationSum.setTransferStationZlljsrp(transferStationZlljsrp+obj.getTransferStationZlljsrp());
        //剩余库存
       
		int balanceTodayYrp  = 0;
		if(isExist){
		   balanceTodayYrp  =  swCkSingleStationSum.getBalanceTodayYrp();
		}
		swCkSingleStationSum.setBalanceTodayYrp(balanceTodayYrp+obj.getBalanceTodayYrp());
		
		int balanceTodaySrp =0;
		if(isExist){
		  balanceTodaySrp= swCkSingleStationSum.getBalanceTodaySrp();
		}
		swCkSingleStationSum.setBalanceTodaySrp(balanceTodaySrp+obj.getBalanceTodaySrp());

		int balanceTodayZlljsrp  = 0;
		if(isExist){
		  balanceTodayZlljsrp = swCkSingleStationSum.getBalanceTodayZlljsrp();
		}
		swCkSingleStationSum.setBalanceTodayZlljsrp(balanceTodayZlljsrp+obj.getBalanceTodayZlljsrp());

		if(isStatOther){
			//统计分票种售卖及库存 的合计值  上日  售卖 剩余小计
            int balanceLastdaySubTotal  = 0;
			if(isExist){
			  balanceLastdaySubTotal = swCkSingleStationSum.getBalanceLastdaySubTotal();
			}
			swCkSingleStationSum.setBalanceLastdaySubTotal(balanceLastdaySubTotal+obj.getBalanceLastdaySubTotal());
			
			int boxOfficeSaleSubtotal  = 0;
			if(isExist){
			  boxOfficeSaleSubtotal = swCkSingleStationSum.getBoxOfficeSaleSubtotal();
			}
			swCkSingleStationSum.setBoxOfficeSaleSubtotal(boxOfficeSaleSubtotal+obj.getBoxOfficeSaleSubtotal());

			int balanceTodaySubtotal  = 0;
			if(isExist){
			   balanceTodaySubtotal = swCkSingleStationSum.getBalanceTodaySubtotal();
			}
			swCkSingleStationSum.setBalanceTodaySubtotal(balanceTodaySubtotal+obj.getBalanceTodaySubtotal());
			
		}

	}

	private List<SwCkDailyTicketSaleExportDTO> combinAttribute(List<Map<String,Object>> list,boolean isDate,boolean isStation ){
		List<SwCkDailyTicketSaleExportDTO> listReturn  = new ArrayList();
		 //循环swStStockList
         for(Map<String,Object> dto : list) {
            SwCkDailyTicketSaleExportDTO swCkSingleStationSum = new SwCkDailyTicketSaleExportDTO();
			if(isDate){
				 swCkSingleStationSum.setTradeDateTostring((String)dto.get("TRADE_DATE_TOSTRING"));
			}
			if(isStation){
				 swCkSingleStationSum.setStationCode((String)dto.get("STATION_CODE"));
				 swCkSingleStationSum.setStationName((String)dto.get("STATION_NAME"));
			}
			//本日结存
			int balanceLastdayYrp  = Integer.parseInt(String.valueOf(dto.get("BALANCE_LASTDAY_YRP")));
			swCkSingleStationSum.setBalanceLastdayYrp(balanceLastdayYrp);
			
			int balanceLastdaySrp  = Integer.parseInt(String.valueOf(dto.get("BALANCE_LASTDAY_SRP")));
			swCkSingleStationSum.setBalanceLastdaySrp(balanceLastdaySrp);

			int balanceLastdayZlljsrp  =Integer.parseInt(String.valueOf(dto.get("BALANCE_LASTDAY_ZLLJSRP")));
			swCkSingleStationSum.setBalanceLastdayZlljsrp(balanceLastdayZlljsrp);
			
			//售卖数量
			int boxOfficeSaleYrp  =Integer.parseInt(String.valueOf(dto.get("BOX_OFFICE_SALE_YRP")));
			swCkSingleStationSum.setBoxOfficeSaleYrp(boxOfficeSaleYrp);
			
			int boxOfficeSaleSrp  = Integer.parseInt(String.valueOf(dto.get("BOX_OFFICE_SALE_SRP")));
			swCkSingleStationSum.setBoxOfficeSaleSrp(boxOfficeSaleSrp);

			int boxOfficeSaleZlljsrp  =Integer.parseInt(String.valueOf(dto.get("BOX_OFFICE_SALE_ZLLJSRP")));
			swCkSingleStationSum.setBoxOfficeSaleZlljsrp(boxOfficeSaleZlljsrp);
			//替换数量
			
			int ticketReplaceYrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_REPLACE_YRP")));
			swCkSingleStationSum.setTicketReplaceYrp(ticketReplaceYrp);
			
			int ticketReplaceSrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_REPLACE_SRP")));
			swCkSingleStationSum.setTicketReplaceSrp(ticketReplaceSrp);

			int ticketReplaceZlljsrp  =Integer.parseInt(String.valueOf(dto.get("TICKET_REPLACE_ZLLJSRP")));
			swCkSingleStationSum.setTicketReplaceZlljsrp(ticketReplaceZlljsrp);

			//上交数量
			
			int ticketHandYrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_HAND_YRP")));
			swCkSingleStationSum.setTicketHandYrp(ticketHandYrp);
			
			int ticketHandSrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_HAND_SRP")));
			swCkSingleStationSum.setTicketHandSrp(ticketHandSrp);

			int ticketHandZlljsrp  =Integer.parseInt(String.valueOf(dto.get("TICKET_HAND_ZLLJSRP")));
			swCkSingleStationSum.setTicketHandZlljsrp(ticketHandZlljsrp);

			//人工回收数量
			
			int ticketRecycleYrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_RECYCLE_YRP")));
			swCkSingleStationSum.setTicketRecycleYrp(ticketRecycleYrp);
			
			int ticketRecycleSrp  = Integer.parseInt(String.valueOf(dto.get("TICKET_RECYCLE_SRP")));
			swCkSingleStationSum.setTicketRecycleSrp(ticketRecycleSrp);

			int ticketRecycleZlljsrp  =Integer.parseInt(String.valueOf(dto.get("TICKET_RECYCLE_ZLLJSRP")));
			swCkSingleStationSum.setTicketRecycleZlljsrp(ticketRecycleZlljsrp);
			//配送数量
			int distributionStationYrp  =Integer.parseInt(String.valueOf(dto.get("DISTRIBUTION_STATION_YRP")));
			swCkSingleStationSum.setDistributionStationYrp(distributionStationYrp);
			
			int distributionStationSrp  =Integer.parseInt(String.valueOf(dto.get("DISTRIBUTION_STATION_SRP")));
			swCkSingleStationSum.setDistributionStationSrp(distributionStationSrp);

			int distributionStationZlljsrp  =Integer.parseInt(String.valueOf(dto.get("DISTRIBUTION_STATION_ZLLJSRP")));
			swCkSingleStationSum.setDistributionStationZlljsrp(distributionStationZlljsrp);
			//调票数量
			int transferStationYrp  = Integer.parseInt(String.valueOf(dto.get("TRANSFER_STATION_YRP")));
			swCkSingleStationSum.setTransferStationYrp(transferStationYrp);
			
			int transferStationSrp  =Integer.parseInt(String.valueOf(dto.get("TRANSFER_STATION_SRP")));
			swCkSingleStationSum.setTransferStationSrp(transferStationSrp);

			int transferStationZlljsrp  =Integer.parseInt(String.valueOf(dto.get("TRANSFER_STATION_ZLLJSRP")));
			swCkSingleStationSum.setTransferStationZlljsrp(transferStationZlljsrp);
			//剩余库存
		   
			int balanceTodayYrp  = Integer.parseInt(String.valueOf(dto.get("BALANCE_TODAY_YRP")));
			swCkSingleStationSum.setBalanceTodayYrp(balanceTodayYrp);
			
			int balanceTodaySrp  = Integer.parseInt(String.valueOf(dto.get("BALANCE_TODAY_SRP")));
			swCkSingleStationSum.setBalanceTodaySrp(balanceTodaySrp);

			int balanceTodayZlljsrp  = Integer.parseInt(String.valueOf(dto.get("BALANCE_TODAY_ZLLJSRP")));
			swCkSingleStationSum.setBalanceTodayZlljsrp(balanceTodayZlljsrp);
			listReturn.add(swCkSingleStationSum);

	}
	 return listReturn;
	}
	
	/**
	  按收益统计--计算合计值
	  obj:  某一日的数据
      swCkSingleStationSum: 车站合计
	*/
	private void adjustIncomeForm(SwCkDailyTicketIncomeExportDTO obj,SwCkDailyTicketIncomeExportDTO swCkSingleStationSum,boolean isStatOther){
            
		
		boolean isExist = false;
		if(swCkSingleStationSum!=null && swCkSingleStationSum.getStationName()!=null){
			isExist = true;
		}
		swCkSingleStationSum.setStationName("合计");
		swCkSingleStationSum.setTradeDateTostring("合计");

		//---------------------------------------------一日票相关----------------------------
		
		//--一日票 现金
		int cashSaleNumYrp  = 0;	
		
		if(isExist){
			cashSaleNumYrp = swCkSingleStationSum.getCashSaleNumYrp();
		}
		swCkSingleStationSum.setCashSaleNumYrp(cashSaleNumYrp+obj.getCashSaleNumYrp());
		
		BigDecimal cashSaleAmountYrp = new BigDecimal(0.00);
		if(isExist){
			cashSaleAmountYrp = swCkSingleStationSum.getCashSaleAmountYrp();
		}		
		swCkSingleStationSum.setCashSaleAmountYrp(cashSaleAmountYrp.add(obj.getCashSaleAmountYrp()));

		//--一日票 POS
		int posSaleNumYrp  = 0;	
		
		if(isExist){
			posSaleNumYrp = swCkSingleStationSum.getPosSaleNumYrp();
		}
		swCkSingleStationSum.setPosSaleNumYrp(posSaleNumYrp+obj.getPosSaleNumYrp());
		
		BigDecimal posSaleAmountYrp = new BigDecimal(0.00);
		if(isExist){
			posSaleAmountYrp = swCkSingleStationSum.getPosSaleAmountYrp();
		}		
		swCkSingleStationSum.setPosSaleAmountYrp(posSaleAmountYrp.add(obj.getPosSaleAmountYrp()));

		//--一日票支付宝
		int alipySaleNumYrp  = 0;	
		
		if(isExist){
			alipySaleNumYrp = swCkSingleStationSum.getAlipySaleNumYrp();
		}
		swCkSingleStationSum.setAlipySaleNumYrp(alipySaleNumYrp+obj.getAlipySaleNumYrp());
		
		BigDecimal alipySaleAmountYrp = new BigDecimal(0.00);
		if(isExist){
			alipySaleAmountYrp = swCkSingleStationSum.getAlipySaleAmountYrp();
		}		
		swCkSingleStationSum.setAlipySaleAmountYrp(alipySaleAmountYrp.add(obj.getAlipySaleAmountYrp()));

		//--一日票微信
		int wechatSaleNumYrp  = 0;	
		
		if(isExist){
			wechatSaleNumYrp = swCkSingleStationSum.getWechatSaleNumYrp();
		}
		swCkSingleStationSum.setWechatSaleNumYrp(wechatSaleNumYrp+obj.getWechatSaleNumYrp());
		
		BigDecimal wechatSaleAmountYrp = new BigDecimal(0.00);
		if(isExist){
			wechatSaleAmountYrp = swCkSingleStationSum.getWechatSaleAmountYrp();
		}		
		swCkSingleStationSum.setWechatSaleAmountYrp(wechatSaleAmountYrp.add(obj.getWechatSaleAmountYrp()));

		//--一日票售卖小计
		int subSaleNumYrp  = 0;	
		
		if(isExist){
			subSaleNumYrp = swCkSingleStationSum.getSubSaleNumYrp();
		}
		swCkSingleStationSum.setSubSaleNumYrp(subSaleNumYrp+obj.getSubSaleNumYrp());
		
		BigDecimal subSaleAmountYrp = new BigDecimal(0.00);
		if(isExist){
			subSaleAmountYrp = swCkSingleStationSum.getSubSaleAmountYrp();
		}		
		swCkSingleStationSum.setSubSaleAmountYrp(subSaleAmountYrp.add(obj.getSubSaleAmountYrp()));

		//---------------------------------------------三日票相关----------------------------
		
		//--三日票 现金
		int cashSaleNumSrp  = 0;	
		
		if(isExist){
			cashSaleNumSrp = swCkSingleStationSum.getCashSaleNumSrp();
		}
		swCkSingleStationSum.setCashSaleNumSrp(cashSaleNumSrp+obj.getCashSaleNumSrp());
		
		BigDecimal cashSaleAmountSrp = new BigDecimal(0.00);
		if(isExist){
			cashSaleAmountSrp = swCkSingleStationSum.getCashSaleAmountSrp();
		}		
		swCkSingleStationSum.setCashSaleAmountSrp(cashSaleAmountSrp.add(obj.getCashSaleAmountSrp()));

		//--三日票 POS
		int posSaleNumSrp  = 0;	
		
		if(isExist){
			posSaleNumSrp = swCkSingleStationSum.getPosSaleNumSrp();
		}
		swCkSingleStationSum.setPosSaleNumSrp(posSaleNumSrp+obj.getPosSaleNumSrp());
		
		BigDecimal posSaleAmountSrp = new BigDecimal(0.00);
		if(isExist){
			posSaleAmountSrp = swCkSingleStationSum.getPosSaleAmountSrp();
		}		
		swCkSingleStationSum.setPosSaleAmountSrp(posSaleAmountSrp.add(obj.getPosSaleAmountSrp()));

		//--三日票支付宝
		int alipySaleNumSrp  = 0;	
		
		if(isExist){
			alipySaleNumSrp = swCkSingleStationSum.getAlipySaleNumSrp();
		}
		swCkSingleStationSum.setAlipySaleNumSrp(alipySaleNumSrp+obj.getAlipySaleNumSrp());
		
		BigDecimal alipySaleAmountSrp = new BigDecimal(0.00);
		if(isExist){
			alipySaleAmountSrp = swCkSingleStationSum.getAlipySaleAmountSrp();
		}		
		swCkSingleStationSum.setAlipySaleAmountSrp(alipySaleAmountSrp.add(obj.getAlipySaleAmountSrp()));

		//--三日票微信
		int wechatSaleNumSrp  = 0;	
		
		if(isExist){
			wechatSaleNumSrp = swCkSingleStationSum.getWechatSaleNumSrp();
		}
		swCkSingleStationSum.setWechatSaleNumSrp(wechatSaleNumSrp+obj.getWechatSaleNumSrp());
		
		BigDecimal wechatSaleAmountSrp = new BigDecimal(0.00);
		if(isExist){
			wechatSaleAmountSrp = swCkSingleStationSum.getWechatSaleAmountSrp();
		}		
		swCkSingleStationSum.setWechatSaleAmountSrp(wechatSaleAmountSrp.add(obj.getWechatSaleAmountSrp()));

		//--三日票售卖小计
		int subSaleNumSrp  = 0;	
		
		if(isExist){
			subSaleNumSrp = swCkSingleStationSum.getSubSaleNumSrp();
		}
		swCkSingleStationSum.setSubSaleNumSrp(subSaleNumSrp+obj.getSubSaleNumSrp());
		
		BigDecimal subSaleAmountSrp = new BigDecimal(0.00);
		if(isExist){
			subSaleAmountSrp = swCkSingleStationSum.getSubSaleAmountSrp();
		}		
		swCkSingleStationSum.setSubSaleAmountSrp(subSaleAmountSrp.add(obj.getSubSaleAmountSrp()));

		//---------------------------------------------昭陵六骏三日票相关----------------------------
		
		//--昭陵六骏三日票 现金
		int cashSaleNumZlljsrp  = 0;	
		
		if(isExist){
			cashSaleNumZlljsrp = swCkSingleStationSum.getCashSaleNumZlljsrp();
		}
		swCkSingleStationSum.setCashSaleNumZlljsrp(cashSaleNumZlljsrp+obj.getCashSaleNumZlljsrp());
		
		BigDecimal cashSaleAmountZlljsrp = new BigDecimal(0.00);
		if(isExist){
			cashSaleAmountZlljsrp = swCkSingleStationSum.getCashSaleAmountZlljsrp();
		}		
		swCkSingleStationSum.setCashSaleAmountZlljsrp(cashSaleAmountZlljsrp.add(obj.getCashSaleAmountZlljsrp()));

		//--昭陵六骏三日票 POS
		int posSaleNumZlljsrp  = 0;	
		
		if(isExist){
			posSaleNumZlljsrp = swCkSingleStationSum.getPosSaleNumZlljsrp();
		}
		swCkSingleStationSum.setPosSaleNumZlljsrp(posSaleNumZlljsrp+obj.getPosSaleNumZlljsrp());
		
		BigDecimal posSaleAmountZlljsrp = new BigDecimal(0.00);
		if(isExist){
			posSaleAmountZlljsrp = swCkSingleStationSum.getPosSaleAmountZlljsrp();
		}		
		swCkSingleStationSum.setPosSaleAmountZlljsrp(posSaleAmountZlljsrp.add(obj.getPosSaleAmountZlljsrp()));

		//--昭陵六骏三日票支付宝
		int alipySaleNumZlljsrp  = 0;	
		
		if(isExist){
			alipySaleNumZlljsrp = swCkSingleStationSum.getAlipySaleNumZlljsrp();
		}
		swCkSingleStationSum.setAlipySaleNumZlljsrp(alipySaleNumZlljsrp+obj.getAlipySaleNumZlljsrp());
		
		BigDecimal alipySaleAmountZlljsrp = new BigDecimal(0.00);
		if(isExist){
			alipySaleAmountZlljsrp = swCkSingleStationSum.getAlipySaleAmountZlljsrp();
		}		
		swCkSingleStationSum.setAlipySaleAmountZlljsrp(alipySaleAmountZlljsrp.add(obj.getAlipySaleAmountZlljsrp()));

		//--昭陵六骏三日票微信
		int wechatSaleNumZlljsrp  = 0;	
		
		if(isExist){
			wechatSaleNumZlljsrp = swCkSingleStationSum.getWechatSaleNumZlljsrp();
		}
		swCkSingleStationSum.setWechatSaleNumZlljsrp(wechatSaleNumZlljsrp+obj.getWechatSaleNumZlljsrp());
		
		BigDecimal wechatSaleAmountZlljsrp = new BigDecimal(0.00);
		if(isExist){
			wechatSaleAmountZlljsrp = swCkSingleStationSum.getWechatSaleAmountZlljsrp();
		}		
		swCkSingleStationSum.setWechatSaleAmountZlljsrp(wechatSaleAmountZlljsrp.add(obj.getWechatSaleAmountZlljsrp()));

		//--昭陵六骏三日票售卖小计
		int subSaleNumZlljsrp  = 0;	
		
		if(isExist){
			subSaleNumZlljsrp = swCkSingleStationSum.getSubSaleNumZlljsrp();
		}
		swCkSingleStationSum.setSubSaleNumZlljsrp(subSaleNumZlljsrp+obj.getSubSaleNumZlljsrp());
		
		BigDecimal subSaleAmountZlljsrp = new BigDecimal(0.00);
		if(isExist){
			subSaleAmountZlljsrp = swCkSingleStationSum.getSubSaleAmountZlljsrp();
		}		
		swCkSingleStationSum.setSubSaleAmountZlljsrp(subSaleAmountZlljsrp.add(obj.getSubSaleAmountZlljsrp()));

		//-----------------------分支付方式合计-----------------------------

		//--分支付方式 现金
		int cashSaleNumPay  = 0;	
		
		if(isExist){
			cashSaleNumPay = swCkSingleStationSum.getCashSaleNumPay();
		}
		swCkSingleStationSum.setCashSaleNumPay(cashSaleNumPay+obj.getCashSaleNumPay());
		
		BigDecimal cashSaleAmountPay = new BigDecimal(0.00);
		if(isExist){
			cashSaleAmountPay = swCkSingleStationSum.getCashSaleAmountPay();
		}		
		swCkSingleStationSum.setCashSaleAmountPay(cashSaleAmountPay.add(obj.getCashSaleAmountPay()));

		//--分支付方式 POS
		int posSaleNumPay  = 0;	
		
		if(isExist){
			posSaleNumPay = swCkSingleStationSum.getPosSaleNumPay();
		}
		swCkSingleStationSum.setPosSaleNumPay(posSaleNumPay+obj.getPosSaleNumPay());
		
		BigDecimal posSaleAmountPay = new BigDecimal(0.00);
		if(isExist){
			posSaleAmountPay = swCkSingleStationSum.getPosSaleAmountPay();
		}		
		swCkSingleStationSum.setPosSaleAmountPay(posSaleAmountPay.add(obj.getPosSaleAmountPay()));

		//--分支付方式支付宝
		int alipySaleNumPay  = 0;	
		
		if(isExist){
			alipySaleNumPay = swCkSingleStationSum.getAlipySaleNumPay();
		}
		swCkSingleStationSum.setAlipySaleNumPay(alipySaleNumPay+obj.getAlipySaleNumPay());
		
		BigDecimal alipySaleAmountPay = new BigDecimal(0.00);
		if(isExist){
			alipySaleAmountPay = swCkSingleStationSum.getAlipySaleAmountPay();
		}		
		swCkSingleStationSum.setAlipySaleAmountPay(alipySaleAmountPay.add(obj.getAlipySaleAmountPay()));

		//--分支付方式微信
		int wechatSaleNumPay  = 0;	
		
		if(isExist){
			wechatSaleNumPay = swCkSingleStationSum.getWechatSaleNumPay();
		}
		swCkSingleStationSum.setWechatSaleNumPay(wechatSaleNumPay+obj.getWechatSaleNumPay());
		
		BigDecimal wechatSaleAmountPay = new BigDecimal(0.00);
		if(isExist){
			wechatSaleAmountPay = swCkSingleStationSum.getWechatSaleAmountPay();
		}		
		swCkSingleStationSum.setWechatSaleAmountPay(wechatSaleAmountPay.add(obj.getWechatSaleAmountPay()));

		//--合计
		int saleNum  = 0;	
		
		if(isExist){
			saleNum = swCkSingleStationSum.getSaleNum();
		}
		swCkSingleStationSum.setSaleNum(saleNum+obj.getSaleNum());
		
		BigDecimal saleAmount = new BigDecimal(0.00);
		if(isExist){
			saleAmount = swCkSingleStationSum.getSaleAmount();
		}		
		swCkSingleStationSum.setSaleAmount(saleAmount.add(obj.getSaleAmount()));

	}

	private List<SwCkDailyTicketIncomeExportDTO> combinIncomeAttribute(List<Map<String,Object>> list,boolean isDate,boolean isStation ){
		List<SwCkDailyTicketIncomeExportDTO> listReturn  = new ArrayList();
		 //循环swStStockList
         for(Map<String,Object> dto : list) {
            SwCkDailyTicketIncomeExportDTO swCkSingleStationSum = new SwCkDailyTicketIncomeExportDTO();
			if(isDate){
				 swCkSingleStationSum.setTradeDateTostring((String)dto.get("TRADE_DATE_TOSTRING"));
			}
			if(isStation){
				 swCkSingleStationSum.setStationCode((String)dto.get("STATION_CODE"));
				 swCkSingleStationSum.setStationName((String)dto.get("STATION_NAME"));
			}
			
			
			int cashSaleNumYrp  = Integer.parseInt(String.valueOf(dto.get("CASH_SALE_NUM_YRP")));
			swCkSingleStationSum.setCashSaleNumYrp(cashSaleNumYrp);
			BigDecimal cashSaleAmountYrp  = new BigDecimal(String.valueOf(dto.get("CASH_SALE_AMOUNT_YRP")));
			swCkSingleStationSum.setCashSaleAmountYrp(cashSaleAmountYrp);

			int posSaleNumYrp  = Integer.parseInt(String.valueOf(dto.get("POS_SALE_NUM_YRP")));
			swCkSingleStationSum.setPosSaleNumYrp(posSaleNumYrp);
			BigDecimal posSaleAmountYrp  = new BigDecimal(String.valueOf(dto.get("POS_SALE_AMOUNT_YRP")));
			swCkSingleStationSum.setPosSaleAmountYrp(posSaleAmountYrp);

			
			int alipySaleNumYrp  = Integer.parseInt(String.valueOf(dto.get("ALIPY_SALE_NUM_YRP")));
			swCkSingleStationSum.setAlipySaleNumYrp(alipySaleNumYrp);
			BigDecimal alipySaleAmountYrp  = new BigDecimal(String.valueOf(dto.get("ALIPY_SALE_AMOUNT_YRP")));
			swCkSingleStationSum.setAlipySaleAmountYrp(alipySaleAmountYrp);

			int wechatSaleNumYrp  = Integer.parseInt(String.valueOf(dto.get("WECHAT_SALE_NUM_YRP")));
			swCkSingleStationSum.setWechatSaleNumYrp(wechatSaleNumYrp);
			BigDecimal wechatSaleAmountYrp  = new BigDecimal(String.valueOf(dto.get("WECHAT_SALE_AMOUNT_YRP")));
			swCkSingleStationSum.setWechatSaleAmountYrp(wechatSaleAmountYrp);

			int subSaleNumYrp  = Integer.parseInt(String.valueOf(dto.get("SUB_SALE_NUM_YRP")));
			swCkSingleStationSum.setSubSaleNumYrp(subSaleNumYrp);
			BigDecimal subSaleAmountYrp  = new BigDecimal(String.valueOf(dto.get("SUB_SALE_AMOUNT_YRP")));
			swCkSingleStationSum.setSubSaleAmountYrp(subSaleAmountYrp);
            //--------------------三日票-----------------
			int cashSaleNumSrp  = Integer.parseInt(String.valueOf(dto.get("CASH_SALE_NUM_SRP")));
			swCkSingleStationSum.setCashSaleNumSrp(cashSaleNumSrp);
			BigDecimal cashSaleAmountSrp  = new BigDecimal(String.valueOf(dto.get("CASH_SALE_AMOUNT_SRP")));
			swCkSingleStationSum.setCashSaleAmountSrp(cashSaleAmountSrp);

			int posSaleNumSrp  = Integer.parseInt(String.valueOf(dto.get("POS_SALE_NUM_SRP")));
			swCkSingleStationSum.setPosSaleNumSrp(posSaleNumSrp);
			BigDecimal posSaleAmountSrp  = new BigDecimal(String.valueOf(dto.get("POS_SALE_AMOUNT_SRP")));
			swCkSingleStationSum.setPosSaleAmountSrp(posSaleAmountSrp);

			
			int alipySaleNumSrp  = Integer.parseInt(String.valueOf(dto.get("ALIPY_SALE_NUM_SRP")));
			swCkSingleStationSum.setAlipySaleNumSrp(alipySaleNumSrp);
			BigDecimal alipySaleAmountSrp  = new BigDecimal(String.valueOf(dto.get("ALIPY_SALE_AMOUNT_SRP")));
			swCkSingleStationSum.setAlipySaleAmountSrp(alipySaleAmountSrp);

			int wechatSaleNumSrp  = Integer.parseInt(String.valueOf(dto.get("WECHAT_SALE_NUM_SRP")));
			swCkSingleStationSum.setWechatSaleNumSrp(wechatSaleNumSrp);
			BigDecimal wechatSaleAmountSrp  = new BigDecimal(String.valueOf(dto.get("WECHAT_SALE_AMOUNT_SRP")));
			swCkSingleStationSum.setWechatSaleAmountSrp(wechatSaleAmountSrp);

			int subSaleNumSrp  = Integer.parseInt(String.valueOf(dto.get("SUB_SALE_NUM_SRP")));
			swCkSingleStationSum.setSubSaleNumSrp(subSaleNumSrp);
			BigDecimal subSaleAmountSrp  = new BigDecimal(String.valueOf(dto.get("SUB_SALE_AMOUNT_SRP")));
			swCkSingleStationSum.setSubSaleAmountSrp(subSaleAmountSrp);
			//----------昭陵六骏三日票-----------------------
			
			int cashSaleNumZlljsrp  = Integer.parseInt(String.valueOf(dto.get("CASH_SALE_NUM_ZLLJSRP")));
			swCkSingleStationSum.setCashSaleNumZlljsrp(cashSaleNumZlljsrp);
			BigDecimal cashSaleAmountZlljsrp  = new BigDecimal(String.valueOf(dto.get("CASH_SALE_AMOUNT_ZLLJSRP")));
			swCkSingleStationSum.setCashSaleAmountZlljsrp(cashSaleAmountZlljsrp);

			int posSaleNumZlljsrp  = Integer.parseInt(String.valueOf(dto.get("POS_SALE_NUM_ZLLJSRP")));
			swCkSingleStationSum.setPosSaleNumZlljsrp(posSaleNumZlljsrp);
			BigDecimal posSaleAmountZlljsrp  = new BigDecimal(String.valueOf(dto.get("POS_SALE_AMOUNT_ZLLJSRP")));
			swCkSingleStationSum.setPosSaleAmountZlljsrp(posSaleAmountZlljsrp);

			
			int alipySaleNumZlljsrp  = Integer.parseInt(String.valueOf(dto.get("ALIPY_SALE_NUM_ZLLJSRP")));
			swCkSingleStationSum.setAlipySaleNumZlljsrp(alipySaleNumZlljsrp);
			BigDecimal alipySaleAmountZlljsrp  = new BigDecimal(String.valueOf(dto.get("ALIPY_SALE_AMOUNT_ZLLJSRP")));
			swCkSingleStationSum.setAlipySaleAmountZlljsrp(alipySaleAmountZlljsrp);

			int wechatSaleNumZlljsrp  = Integer.parseInt(String.valueOf(dto.get("WECHAT_SALE_NUM_ZLLJSRP")));
			swCkSingleStationSum.setWechatSaleNumZlljsrp(wechatSaleNumZlljsrp);
			BigDecimal wechatSaleAmountZlljsrp  = new BigDecimal(String.valueOf(dto.get("WECHAT_SALE_AMOUNT_ZLLJSRP")));
			swCkSingleStationSum.setWechatSaleAmountZlljsrp(wechatSaleAmountZlljsrp);

			int subSaleNumZlljsrp  = Integer.parseInt(String.valueOf(dto.get("SUB_SALE_NUM_ZLLJSRP")));
			swCkSingleStationSum.setSubSaleNumZlljsrp(subSaleNumZlljsrp);
			BigDecimal subSaleAmountZlljrp  = new BigDecimal(String.valueOf(dto.get("SUB_SALE_AMOUNT_ZLLJSRP")));
			swCkSingleStationSum.setSubSaleAmountZlljsrp(subSaleAmountZlljrp);

			//---分支付方式-----

            int cashSaleNumPay  = Integer.parseInt(String.valueOf(dto.get("CASH_SALE_NUM_PAY")));
			swCkSingleStationSum.setCashSaleNumPay(cashSaleNumPay);
			BigDecimal cashSaleAmountPay  = new BigDecimal(String.valueOf(dto.get("CASH_SALE_AMOUNT_PAY")));
			swCkSingleStationSum.setCashSaleAmountPay(cashSaleAmountPay);

			int posSaleNumPay  = Integer.parseInt(String.valueOf(dto.get("POS_SALE_NUM_PAY")));
			swCkSingleStationSum.setPosSaleNumPay(posSaleNumPay);
			BigDecimal posSaleAmountPay = new BigDecimal(String.valueOf(dto.get("POS_SALE_AMOUNT_PAY")));
			swCkSingleStationSum.setPosSaleAmountPay(posSaleAmountPay);

			
			int alipySaleNumPay  = Integer.parseInt(String.valueOf(dto.get("ALIPY_SALE_NUM_PAY")));
			swCkSingleStationSum.setAlipySaleNumPay(alipySaleNumPay);
			BigDecimal alipySaleAmountPay  = new BigDecimal(String.valueOf(dto.get("ALIPY_SALE_AMOUNT_PAY")));
			swCkSingleStationSum.setAlipySaleAmountPay(alipySaleAmountPay);

			int wechatSaleNumPay  = Integer.parseInt(String.valueOf(dto.get("WECHAT_SALE_NUM_PAY")));
			swCkSingleStationSum.setWechatSaleNumPay(wechatSaleNumPay);
			BigDecimal wechatSaleAmountPay  = new BigDecimal(String.valueOf(dto.get("WECHAT_SALE_AMOUNT_PAY")));
			swCkSingleStationSum.setWechatSaleAmountPay(wechatSaleAmountPay);
            //合计
			int saleNum  = Integer.parseInt(String.valueOf(dto.get("SALE_NUM")));
			swCkSingleStationSum.setSaleNum(saleNum);
			BigDecimal saleAmount  = new BigDecimal(String.valueOf(dto.get("SALE_AMOUNT")));
			swCkSingleStationSum.setSaleAmount(saleAmount);			
			
			listReturn.add(swCkSingleStationSum);

	}
	 return listReturn;
	}
}
